﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Applib;
using Yule8xCommon.Db;
using Yule8xCommon.Typelib;
using Yule8xModel;

namespace Yule8xWechat.Test
{
    public partial class Agent2Detail : System.Web.UI.Page
    {
        protected System.Data.DataTable dtList;
        protected WxUserInfoResult wxUser;
        protected int todaycount, totalcount;
        protected decimal todayamount, totalamount;
        protected void Page_Load(object sender, EventArgs e)
        {
            int user_id = RequestUtil.GetInteger("user_id");
            if (user_id < 1)
            {
                Response.Write("请输入user_id参数");
                Response.End();
            }
            wxUser = UserModels.GetWxUserInfo(user_id);
            if (null == wxUser)
            {
                Response.Write("未登录");
                Response.End();
            }

            string sqlstmt = string.Format("select child2_agent_count_today, child2_agent_count, child2_agent_income_today, child2_agent_income_total from t_user_agent_statistics where user_id={0}", wxUser.user_id);
            System.Data.DataTable dt = DbFactory.Init(AppInfo.conn_yule8x_agent).ExecuteDataTable(sqlstmt);
            todaycount = DataTableUtil.GetInteger(dt, "child2_agent_count_today");
            totalcount = DataTableUtil.GetInteger(dt, "child2_agent_count");
            // 2级代理今日收入统计
            sqlstmt = string.Format("select sum(rebate_amount_today) from t_agent2_statistics where user_id={0}", wxUser.user_id);
            todayamount = decimal.Parse(DbFactory.Instance.GetValue(sqlstmt, "0").ToString());
            //todayamount = DataTableUtil.GetDecimal(dt, "child2_agent_income_today");
            // 2级代理累计收入统计
            sqlstmt = string.Format("select sum(rebate_amount_total) from t_agent2_statistics where user_id={0}", wxUser.user_id);
            totalamount = decimal.Parse(DbFactory.Instance.GetValue(sqlstmt, "0").ToString());

            sqlstmt = string.Format("select u.nickname, s.rebate_amount_today, s.rebate_amount_total from t_agent2_statistics s left join t_user u on s.agent2_id=u.user_id where s.user_id={0}", wxUser.user_id);
            dtList = DbFactory.Instance.ExecuteDataTable(sqlstmt);
        }
    }
}